﻿#region Copyright
/// <copyright>
/// Copyright (c) 2008 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Osh.Dvb
{
	/// <summary>
	/// GenericDescriptor is a class which can be used to encapsulation data for unknown program descriptors.
	/// </summary>
	public class GenericDescriptor : Descriptor
	{
		private byte[] _data;

		/// <summary>
		/// Creates a descriptor with tag and data.
		/// </summary>
		/// <param name="tag">Tag of the descriptor.</param>
		/// <param name="body">Body of the descriptor.</param>
		public GenericDescriptor(byte tag, byte[] body)
			: base(tag, body.Length)
		{
			_data = body;
		}

		public GenericDescriptor(byte tag, byte[] buffer, int offset, int length)
			: base(tag, length)
		{
			_data = new byte[length];
			Array.Copy(buffer, offset, _data, 0, length);
		}

		public byte[] Data
		{
			get { return _data; }
			set
			{
				if(value == null)
					throw new ArgumentNullException("value");
				if(value.Length > MaxBodyLength)
					throw new ArgumentOutOfRangeException("value");
				_data = value;
				base.BodyLength = (byte)value.Length;
			}
		}
	}
}
